package com.wh.data.model.exe;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

/**
 */
public class FilePathProcessor {

    // all member store absolute path
    private String _rootPath = ""; //$NON-NLS-1$

    /**
     * @param root
     * 
     * @throws FileNotFoundException
     */
    public FilePathProcessor(String root) throws FileNotFoundException {
	File rootDir = new File(root);
	if (!rootDir.exists() || rootDir.list() == null)
	    throw new FileNotFoundException();
	this._rootPath = root;
	rootDir = null;
    }

    /**
     * 
     * @return List<String>
     */
    public List<String> getFirstLevelDir() {
	ArrayList<String> canDir = new ArrayList<String>();
	File root = new File(this._rootPath);
	String[] pathArr = root.list();
	for (String path : pathArr) {
	    path = root.getPath() + File.separator + path;
	    File canFile = new File(path);
	    String fileName = canFile.getName();
	    if (canFile.list() == null
		    || !fileName.matches("[0-9]\\..*Therapist.*Location")) { //$NON-NLS-1$
		canFile = null;
		continue;
	    }
	    canDir.add(path);
	}
	root = null;
	return canDir;
    }

    /**
     * Method get2ndLevelDir.
     * 
     * @param abPath
     *            String
     * @return List<String>
     */
    @SuppressWarnings("static-method")
    public List<String> get2ndLevelDir(String abPath) {
	ArrayList<String> canDir = new ArrayList<String>();
	File root = new File(abPath);
	String[] pathArr = root.list();
	for (String path : pathArr) {
	    path = root.getPath() + File.separator + path;
	    File canFile = new File(path);
	    String fileName = canFile.getName();
	    if (canFile.list() == null || !fileName.matches("[0-9]*x[0-9]*")) { //$NON-NLS-1$
		canFile = null;
		continue;
	    }
	    canDir.add(path);
	}
	root = null;
	return canDir;
    }

    /**
     * Method get3rdLevelDir.
     * 
     * @param abPath
     *            String
     * @return List<String>
     */
    @SuppressWarnings("static-method")
    public List<String> get3rdLevelDir(String abPath) {
	ArrayList<String> canDir = new ArrayList<String>();
	File root = new File(abPath);
	String[] pathArr = root.list();
	for (String path : pathArr) {
	    path = root.getPath() + File.separator + path;
	    File canFile = new File(path);
	    String fileName = canFile.getName();
	    if (canFile.list() == null || !fileName.matches("[0-9]*")) { //$NON-NLS-1$
		canFile = null;
		continue;
	    }
	    canDir.add(path);
	}
	root = null;
	return canDir;
    }
}
